<?php

/**
 * Created by EPP.
 * User: yuxun
 * Date: 18/6/26
 * Time: 21:21
 */
class MessageController extends AdminBaseController {
	
	public function index(){
		$this->setTitle('意见反馈列表');
	
		$filter = new PubFilter();
		$grid   = new PubGrid();
	
		$filter->addSeaSpecialFilter(true);
		$filter->addSeaOsFilterAll();
		$filter->addOssServerAll();
		$filter->addFilter('role_id', 'input', '角色ID');
		$filter->addFilter('role_name', 'input', '角色名称');
		
		$filter->addFilter('br', 'br');
		
		$filter->addFilter('begin', 'input', '反馈时间', array('date' => 'day'))
		->addFilter('end', 'input', '至', array('date' => 'day'));
		
		$filter->addFilter('desc', 'input', '反馈内容');
	
		$params = $filter->get();
		$page = $this->R('page', '1');
		$m = $this->R('m');
		$params['m'] = $m;
		$header = MessageService::indexHeader();
		if(PubFunc::isAjax()){
			$result = MessageService::indexData($params);
			$this->out = array(
					'count'     => $result['count'],
					'data'      => $result['data'],
					'result'    => true
			);
			$this->outType = 'json';
		}else{
			$order  = 'create_time';
			$url = PubFunc::ajaxUrl("?r=message/index", $params);
			$grid->addGrid($header, $url, array(
					'name'=>'数据',
					'order'=>array($order, 'desc'),
					'type'=>'message/index',
					'length'=>50,
					'page'=>$page
			));
	
			$this->out['filter'] = $filter->show();
			$this->out['grid'] = $grid->show();
	
		}
	}
	
	public function delete(){
		$id = $this->R('id');
	
		$result = MessageService::delete($id);
	
		if($result !== false){
			$this->showMessage('删除成功', PubFunc::buildBackUrl("/oss/?r=message/index"));
		}else{
			$this->showMessage('删除失败');
		}
	}
    
    
    public function reply(){
    	if(PubFunc::isAjax()){
    		$ar = PubRequest::AR();
    		$out = MessageService::reply($ar);
    		$this->out = $out;
    		$this->outType = 'json';
    	}else{
    		$this->layout = '';
    		 
    		$id = PubRequest::R('id');
    		$this->out['id'] = $id;
    		 
    		$replyTemplateList = ReplyTemplateService::getList();
    		$this->out['replyTemplateList'] = $replyTemplateList;
    	}
    	
    }
    
    public function reply_view(){
    	$this->layout = '';
    	$message_id = PubRequest::R('id');
    	$list = MessageService::reply_view($message_id);
    	$this->out['list'] = $list;
    }

    

}